import request from '@/utils/request';
import { getToken } from "@/utils/auth";

// 查询字典
export function getDataList(keyword, pageNum, pageSize = 20) {
  return request({
    url: process.env.VUE_APP_SERVICE_NAME + 'api/sysEnumDictionary/getListByPage',
    method: 'post',
    data: {
      operationId: getToken(),
      queryStr: keyword,
      pageNum: pageNum,
      recordNum: pageSize
    }
  });
}

// 删除字典
export function deleteSelectedData(ids) {
  return request({
    url: process.env.VUE_APP_SERVICE_NAME + 'api/sysEnumDictionary/deleteByList',
    method: 'post',
    data: {
      operationId: getToken(),
      keyValues: ids
    }
  });
}

export function save(data) {
  let url = process.env.VUE_APP_SERVICE_NAME + 'api/sysEnumDictionary/create';
  const postObj = {
    "createUserId": (data.objectId ? data.createUserId : getToken()),
    "modificationUserId": getToken(),
    "sort": data.sort,
    "tableName": data.tableName,
    "itemName": data.itemName,
    "itemValue": data.itemValue,
    "itemPhoto": data.itemPhoto ? data.itemPhoto : '',
    "remark": data.remark
  };
  if (data.objectId) {
    postObj.objectId = data.objectId;
    url = process.env.VUE_APP_SERVICE_NAME + 'api/sysEnumDictionary/update'
  }
  return request({
    url: url,
    method: 'post',
    data: postObj
  });
}
